home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / thor / SafeEdit.lha / SafeEdit.thor < prev   
Encoding:
Text File  |  1998-10-19  |  3.1 KB  |  115 lines

  1. /*
  2. $VER: SafeEdit.thor 1.3 (19.10.98)
  3. by Neil Bothwick
  4. */
  5. /*
  6. Freezes an event before starting the editor, to prevent
  7. unedited mails being sent out
  8.  
  9. You must define your editor command in ENVARC:THOR/Editor
  10. The editor *must* be started with s sticky option, or the
  11. script will fail to work as needed
  12.  
  13. 1.1 Added check on whether file had been altered on exit
  14.  
  15. 1.2 Added ADDUSER switch to add the recipient to the User Database
  16.  
  17. 1.3 The script was assuming rexxdossupport.library was already
  18.     available, thnks to Gian Maria Calzolari for pointing this out
  19. */
  20.  
  21.  
  22. options results
  23. parse arg arguments
  24.  
  25. /* ;;; Read edit command */
  26. if ~open(ec,'ENV:THOR/Editor','R') then call ExitMsg('Unable to read ENV:THOR/Editor*NHave you set it?')
  27. EditCmd = readln(ec)
  28. call close(ec)
  29. ;;;
  30. /* ;;; Make sure bbsread.library and rexxdossupport.library are accessible from arexx */
  31. if ~show('p', 'BBSREAD') then do
  32.     address command
  33.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  34.     'WaitForPort BBSREAD'
  35.     end
  36. if ~show('L','rexxdossupport.library') then do
  37.     if ~addlib('rexxdossupport.library',0,-30,0) then call ExitMsg('Failed to open rexxdossupport.library')
  38.     end
  39. ;;;
  40. /* ;;; Get Thor arexx port and system name */
  41. portlist = ' '||show('P')
  42. thorpos = pos(' THOR.',portlist)
  43. if thorpos = 0 then call ExitMsg('SafeEd must be called from within Thor')
  44. parse var portlist t1 =thorpos thorport .
  45. address(thorport)
  46. drop TMP.
  47. 'CURRENTSYSTEM stem TMP'
  48. SystemName = TMP.BBSNAME
  49. ;;;
  50. /* ;;; Parse arguments */
  51. drop ARGS.
  52. template = 'TEXTFILE/A,ADDUSER/S'
  53. address BBSREAD
  54. 'READARGS' template 'ARGS CMDLINE' arguments
  55. AddUser = ARGS.ADDUSER
  56. TextFile =  ARGS.TEXTFILE
  57. ;;;
  58. /* ;;; Search event list for event number */
  59. address BBSREAD
  60. GETBBSDATA SystemName SystemData
  61. EventFound = 0
  62. do EventNo = SystemData.LASTEVENT to SystemData.FIRSTEVENT by -1
  63.     drop EventData.
  64.     drop EventTags.
  65.     READBREVENT '"'SystemName'"' eventnr EventNo tagsstem EventTags
  66.     if SystemData.BBSPATH||EventTags.MSGFILE = TextFile then do
  67.         EventFound = 1
  68.         leave
  69.         end
  70.     end
  71. if EventFound = 0 then call ExitMsg('Event not found')
  72. ;;;
  73.  
  74. /* ;;; Add user to database if required */
  75. if AddUser = 1 then do
  76.     address 'BBSREAD'
  77.     drop USER.
  78.     USER.NAME = EventTags.TONAME
  79.     USER.ADDRESS = EventTags.TOADDR
  80.     USER.COMMENT.COUNT = 1
  81.     USER.COMMENT.1 = 'Added by SafeEdit'
  82.     'WRITEBRUSER bbsname "'SystemName'" stem USER ONLYIFEXIST'
  83.     end
  84. ;;;
  85. /* ;;; Freeze event, run editor synchronously, then unfreeze it */
  86.  
  87. del = 0
  88. TimeStamp = subword(statef(TextFile),5,3)
  89. UPDATEBREVENT '"'SystemName'"' EventNo SETFREEZE
  90.     do forever
  91.     address command EditCmd TextFile
  92.     if subword(statef(TextFile),5,3) ~= TimeStamp then leave
  93.     address(thorport)
  94.     'REQUESTNOTIFY "Message text has not been saved" "_Edit|_Delete|_Continue"'
  95.     response = result
  96.     if response = 2 then Del = 1
  97.     if response ~= 1 then leave
  98.     end
  99.  
  100. address BBSREAD
  101. if Del = 1 then 'UPDATEBREVENT "'SystemName'"' EventNo 'SETDELETED'
  102. else 'UPDATEBREVENT "'SystemName'"' EventNo 'CLEARFREEZE'
  103. ;;;
  104.  
  105. exit
  106.  
  107. /* ;;; Exit with a message */
  108. ExitMsg:
  109.     parse arg msg
  110.     address command 'RequestChoice >NIL: "SafeEdit" "'msg'" "Continue"'
  111.     exit
  112.     return
  113. ;;;
  114.  
  115.